package com.xiao.service.Impl;

import com.xiao.dao.CreateClassMapper;
import com.xiao.dao.UserMapper;
import com.xiao.pojo.*;
import com.xiao.service.CreateClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/*创建者：流汗文
创建时间：6.29 10.48
作用：创建班级
 */
@Service
public class    CreateClassServiceImpl implements CreateClassService {
    @Autowired
    private CreateClassMapper createClassMapper;
    @Autowired
    private UserMapper userMapper;

    //获得所有年级类型与年级
    @Override
    public List<Gradetype> FindAllGradetype() {
        return createClassMapper.findgradeandtype();
    }

    //创建班级
    @Override
    public boolean createclassone(String classname, String gradename, String subjectname, String schoolname,long uid) {
        int findgradeid = createClassMapper.findgradeid(gradename);
        int findsubjectid = createClassMapper.findsubjectid(subjectname);
        int findschoolid = createClassMapper.findschoolid(schoolname);
        if (createClassMapper.createclassname(classname,findgradeid,findsubjectid,findschoolid,uid)>0){
            return true;
        }
        return false;
    }
    //

   //创建考试
    @Override
    public boolean createexam(String classname, String subjectname, String examtypename, String examname) {
        int findclassid = createClassMapper.findclassid(classname);
        int findsubjectid = createClassMapper.findsubjectid(subjectname);
        int findexamtypeid = createClassMapper.findexamtypeid(examtypename);
        if (createClassMapper.createexam(findclassid,findsubjectid,examname,findexamtypeid)>0){
            return true;
        }
        return false;
    }
//通讯录第一部分
//    @Override
//    public List<User> phonebookone(Classinfo classinfo, List<User> list) {
//        if (createClassMapper.findourclassuid(classinfo.getClassid()).size()>0){
//            List<User> findstudentinfo = createClassMapper.findstudentinfo(list);
//            return findstudentinfo;
//        }
//        return null;
//    }


  //通讯录第二部分     修改权限学生部分
    @Override
    public boolean updatestudentpower(long uid) {

        return createClassMapper.updateweimointer(uid)>0;
    }
    //通讯录第二部分    修改权限老师部分
    @Override
    public boolean updateteachersubjectid(long uid, String subjectname) {
        int querysubjectid = createClassMapper.querysubjectid(subjectname);
        if (createClassMapper.updatestudentsubjectid(uid,querysubjectid)>0){
            return true;
        }
        return false;
    }
//通讯录模糊查
    @Override
    public List<User> phonebooksearch(int classid, String nickname) {
        return createClassMapper.queryuser(nickname,classid);
    }
//通讯录查询所有信息
    @Override
    public List<User> findallinfo(Long classid) {
        return createClassMapper.findallinfo(classid);
    }
}
